package letter

const testVersion = 1

func T(letter string) (r map[rune]int) {
	r = make(map[rune]int)
	for _, v := range letter {
		r[v]++
	}

	return
}

func ConcurrentFrequency(letters []string) (r FreqMap) {
	r = FreqMap{}
	ch := make(chan map[rune]int)
	go func(lets []string) {
		for i := 0; i < len(lets); i++ {
			ch <- T(lets[i])
		}

		close(ch)
	}(letters)

	for l := range ch {
		for k, _ := range l {
			if _, ok := r[k]; ok {
				r[k] = r[k] + l[k]
			} else {
				r[k] = l[k]
			}
		}
	}

	return
}
